<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>INA Admin V{$INA.version}</title>
<base href="{$INA.admin}" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="{$INA.adminTemplate}general.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="{$INA.adminTemplate}javascript/scripts.js"></script>
<script language="JavaScript" type="text/javascript" src="{$INA.templates}jscripts/ajaxRequest.js"></script>
{if $newBlock}
<script language="JavaScript" type="text/javascript">
    //make sure there is no "no props" row
    //parent.deleteRow('nodata');
    if(window.opener.document.getElementById('nodata')){ldelim}
        var em=window.opener.document.getElementById('nodata');
        em.parentNode.removeChild(em);
    {rdelim}
    
	//add new row to table
	if(!window.opener.document.getElementById('datarow_{$data.tag}')){ldelim}
        var myRows  =   window.opener.document.getElementById('available_data').rows.length;
        var myTable =   window.opener.document.getElementById('available_data').insertRow(myRows);
        var myCellN =   myTable.insertCell(0);
    
        myCellN.innerHTML = '<a href="javascript: editData(\'{$data.id}\',\'{$smarty.get.node}\',\'{$smarty.get.page}\');">{$data.title}</a> [<a href="javascript: deleteData(\'{$data.id}\',\'{$smarty.get.node}\',\'{$smarty.get.page}\',\'{$data.tag}\');" class="admin">x</a>]';
        myCellN.id        = 'datatitle_{$data.tag}';
        myTable.id        = 'datarow_{$data.tag}';
	{rdelim}else{ldelim}
	    window.opener.document.getElementById('datatitle_{$data.tag}').innerHTML = '<a href="javascript: editData(\'{$data.id}\',\'{$smarty.get.node}\',\'{$smarty.get.page}\');">{$data.title}</a> [<a href="javascript: deleteData(\'{$data.id}\',\'{$smarty.get.node}\',\'{$smarty.get.page}\',\'{$data.tag}\');" class="admin">x</a>]'; 
	{rdelim}
    
    window.opener.Fat.fade_element('datarow_{$data.tag}',10,1000,"#ffffcc");
    
    //restore the view
    //window.opener.document.unhide(); 
    window.opener.document.getElementById('adddatabtn').style.display="";
    //window.opener.document.hide('adddataform');
    window.opener.document.getElementById('adddataform').style.display="none";
</script>
{/if}

{if $updateBlock}
<script language="JavaScript" type="text/javascript">
    //update row ids
    window.opener.document.getElementById('datatitle_{$data.oldTag}').id = 'datatitle_{$data.tag}';
    window.opener.document.getElementById('datarow_{$data.oldTag}').id = 'datarow_{$data.tag}';
    
    //update title
    window.opener.document.getElementById('datatitle_{$data.tag}').innerHTML = '<a href="javascript: editData(\'{$data.id}\',\'{$smarty.get.node}\',\'{$smarty.get.page}\');">{$data.title}</a> [<a href="javascript: deleteData(\'{$data.id}\',\'{$smarty.get.node}\',\'{$smarty.get.page}\',\'{$data.tag}\');" class="admin">x</a>]';
</script>
{/if}

{literal}
<script language="JavaScript" type="text/javascript">
    function checkKey(nodeid,pageid,blockid){
        var myVal = document.getElementById('dataTag').value;
        if(!isValidKey(myVal)){
            alert('The defined tag is not valid! It shall not contain spaces or any special characters!');
        }else{
            
            //check if this tag is already taken at that node
            (new AjaxRequest).send({
            		url			: urlBase+"action=checkDatablockTag",
            		data		: {
            			node    : nodeid,
            			page    : pageid,
            			tag     : myVal,
            			block   : blockid
            		},
            		
            		onSuccess	: function(data, info)
            		{
            			if(data["status"] == true){
            			    alert('There is already a datablock with the tag "'+myVal+'", titled "'+data["title"]+'"! Please choose another tag.');
            			}else{
            			    disableButton('save');
                            document.datablockdata.submit();
            			}
            		}
            });
        }
    }
</script>
{/literal}

{literal}
<style>
    #elm1{
        width: 99%;
        height: 230px;
        color: #fff;
        font-size: 10px;
    }
    
    .textinput{
        width: 99%;
    }
    
    body{
        text-align: left;
        margin: 10px;
    }
</style>
{/literal}
</head>

<body>
{include file=tinymceinit.html}
{if $smarty.get.confirm}
    <div id="confirm">
        All data was successfully saved!
    </div>
{/if}
<form method="post" name="datablockdata" class="editform" action="{$INA.this}?action={$smarty.get.action}&node={$smarty.get.node}&page={$smarty.get.page}&block={$smarty.get.block}" onsubmit="disableButton('save');">
<label for="dataTitle">Title:</label>
<input type="text" name="title" class="textinput" value="{$data.title|sslash}" id="dataTitle" />

<label for="dataTag">Tag (no spaces or special characters):</label>
<input type="text" name="tag" class="textinput" value="{$data.tag|sslash}" id="dataTag" {if $data.tag}disabled{/if} />

<label for="elm1">Content:</label>
<textarea id="elm1" name="content" rows="10" cols="40">
   {$data.content|sslash}
</textarea>

<FIELDSET id="datablocks">
    <LEGEND>Options</LEGEND>
        {if $smarty.get.node and !$smarty.get.page}
            <label for="inherit">Inherit:</label>
            <input type="checkbox" id="inherit" name="inherit" value="1" {if $inherit == 't'}checked{/if} {if $nochange}disabled{/if} />
        {/if}
        <label for="global">Global:</label>
        <input type="checkbox" id="global" name="global" value="1" {if $data.global == 't'}checked{/if} {if $nochange}disabled{/if} />
</FIELDSET>

<div align="center">
    <input type="button" name="save" value="Save Changes" id="save" onclick="checkKey('{$smarty.get.node}','{$smarty.get.page}','{$smarty.get.block}');" class="button" />
</div>
</form>
</body>
</html>